package com.hadoop.mapreduce.wordcount;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;


public class WordCountCombiner  extends Reducer<Text,IntWritable,Text,IntWritable>{
    @Override
    protected void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
        //定义一个计数器
        int count=0;
        //遍历这一组kv的所有v，累加到count中
        for (IntWritable intWritable:values
                ) {
            count+=intWritable.get();
        }
        context.write(key,new IntWritable(count));
    }
}
